// 递增运算符++重载
#include <iostream>
using namespace std;
class MyInteger {
    friend ostream& operator<<(ostream& cout, const MyInteger &myinteger);
private:
    int m_num;
public:
    MyInteger();
    MyInteger(int num);
    // 重载前置++
    MyInteger& operator++() {
        ++this->m_num;
        // 这里返回对象，不返回int，为了能够多层++
        return *this;
    }

    // 重载后置++
    // int为占位参数，用来区分++前后置
    MyInteger operator++(int) {
        MyInteger temp = *this;
        ++this->m_num;
        return temp;
    }
};
MyInteger::MyInteger() {}
MyInteger::MyInteger(int num) {
    this->m_num = num;
}
// 全局函数重载左移运算符
ostream& operator<<(ostream& cout, const MyInteger &myinteger) {
    cout << "num: " << myinteger.m_num;
    return cout;
}
void test1() {
    MyInteger mi1(20);
    cout << mi1 << endl;
    cout << ++(++mi1) << endl;

    int a = 5;
    cout << ++(++(++a)) << endl;
    
}
void test2() {
    MyInteger mi2(40);
    cout << mi2 << endl;
    cout << (mi2++)++ << endl;
    cout << mi2 << endl;

    int a = 15;
    // cout << (a++)++ << endl;  // 错误：表达式必须是可修改的左值
}
int main(void) {
    test1();
    test2();

    return 0;
}